﻿using System;
using System.Windows;
using System.Windows.Controls;
using BaseControls;

namespace HOG.Controls
{
    public partial class OptionsControl : UserControl
    {
        public OptionsControl(FrameControl control)
        {
            InitializeComponent();
            frameControl = control;
        }
        public void SetValues(double brightness, double contrast, double gamma)
        {
            lblBrightness.Value = brightness;
            this.brightness.Brightness = brightness;
            lblContrast.Value = contrast;
            this.contrast.Contrast = contrast;
            lblGamma.Value = gamma;
            this.gamma.Gamma = gamma;
        }
        void setDefaultOptionsValues()
        {
            //contrast.Contrast = 1.0;
            //brightness.Brightness = 0.0;
            //gamma.Gamma = 1;
            lblBrightness.Value = 0.0;
            lblContrast.Value = 1.0;
            lblGamma.Value = 1;
        }
        private FrameControl frameControl;
        private void Button_Ok(object sender, RoutedEventArgs e)
        {
            if (frameControl == null)
                frameControl = (FrameControl)(this.Parent as Panel).FindName("FrameControl");
            if (frameControl != null)
            {
                (frameControl as IHudGameInterface).GetClock().UnPause();
                frameControl.brightness.Brightness = brightness.Brightness;
                frameControl.contrast.Contrast = contrast.Contrast;
                frameControl.gamma.Gamma = gamma.Gamma;
                ((this.Parent) as Canvas).Children.Remove(this);
                if (Close != null)
                    Close(null, null);
            }
        }
        public EventHandler Close;

        void shadersControl_ContrastChanged(double value)
        {
            if (contrast != null)
                contrast.Contrast = value;
        }

        void shadersControl_GammaChanged(double value)
        {
            if (gamma != null)
                gamma.Gamma = value;
        }

        void shadersControl_BrightnessChanged(double value)
        {
            if (brightness != null)
                brightness.Brightness = value;
        }

        private void lblGamma_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            shadersControl_GammaChanged(e.NewValue);
        }

        private void lblBrightness_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            shadersControl_BrightnessChanged(e.NewValue);
        }

        private void lblContrast_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            shadersControl_ContrastChanged(e.NewValue);
        }

        private void Button_Default(object sender, RoutedEventArgs e)
        {
            setDefaultOptionsValues();
        }
    }
}
